package com.zp.crm.service.KhService.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zp.crm.dao.JwjlDao.JwjlDao;
import com.zp.crm.dao.KhDao.KhDao;
import com.zp.crm.dao.LxrDao.LxrDao;
import com.zp.crm.dto.Kh.KhDto;
import com.zp.crm.entity.KhEntity.KhEntity;
import com.zp.crm.service.KhService.KhService;
import com.zp.crm.util.targetLog.Log;
@Service("khService")
public class KhServiceImpl implements KhService{
	
	@Resource
	public KhDao khdao;
	@Resource
	public LxrDao lDao;
	@Resource
	public JwjlDao jDao;
	@Log(name="查询客户信息，并根据状态查询")
	@Override
	public Map<String, Object> selectPage(int page, int size,String stuts) {
		int PageIndex=(page-1)*10;
		
		int count=khdao.selectcount(stuts);
		
		List<KhEntity> list=khdao.selectPage(PageIndex,size,stuts);
		
		String a=new KhDto().Html(count,list,PageIndex,0);
		
		Map<String, Object> map=new HashMap<>();
		
		map.put("message", a);
		
		return map;
	}
	@Log(name="查询客户信息列表，可选择查询，并分页。 ")
	@Override
	public Map<String, Object> selectCreatePage(String code, String name, String dq, int page, int size,String stuts) {
		int PageIndex=(page-1)*10;
		
		int count=khdao.selectCreatecount(code,name,dq,stuts);
		
		List<KhEntity> list=khdao.selectCreatePage(code,name,dq,PageIndex,size,stuts);
		
		String a=new KhDto().Html(count,list,PageIndex,1);
		
		Map<String, Object> map=new HashMap<>();
		
		map.put("message", a);
		
		return map;
	}
	@Log(name="根据编号查询指定客户信息 ")
	@Override
	public Map<String, Object> selectBycode(String code) {
		Map<String, Object> map=new HashMap<>();
		if(code != null){
			KhEntity entity=khdao.selectBycode(code);
			if(entity != null){
				map.put("success", true);
				map.put("message", entity);
			}else{
				map.put("success", false);
				map.put("message", "系统繁忙！请刷新从试！");
			}
			
		}else{
			map.put("success", false);
			map.put("message", "格式错误！请从试！");
		}
		return map;
	}
	@Log(name="修改客户信息 ")
	@Override
	public Map<String, Object> edit(KhEntity entity) {
		Map<String,Object> map=new HashMap<>();
		int r=khdao.edit(entity);
		if(r>0){
			map.put("success", true);
			map.put("message", "修改成功！");
		}else{
			map.put("success", false);
			map.put("message", "修改失败！");
		}
		return map;
	}
	@Log(name="删除客户信息")
	@Override
	public Map<String, Object> delete(String code) {
		Map<String, Object> map=new HashMap<>();
		if(code != null){
			int r=khdao.deleteCode(code);
			if(r>0){
				jDao.deleteCode(code);
				lDao.deleteCode(code);
				map.put("success", true);
				map.put("message", "删除成功！");
			}else{
				map.put("success", false);
				map.put("message", "删除失败！请刷新后从试！");
			}
		}else{
			map.put("success", false);
			map.put("message", "格式错误！请从试！");
		}
		return map;
	}
	@Log(name="添加客户信息")
	@Override
	public Map<String, Object> insert(KhEntity entity) {
		Map<String,Object> map=new HashMap<>();
		int r=khdao.insert(entity);
		if(r>0){
			map.put("success", true);
			map.put("message", "添加成功！");
		}else{
			map.put("success", false);
			map.put("message", "添加失败！");
		}
		return map;
	}
}
